package cn.kgc.qnbbs.service;

import cn.kgc.qnbbs.mapper.DetailMapper;
import cn.kgc.qnbbs.mapper.SortMapper;
import cn.kgc.qnbbs.pojo.Detail;
import cn.kgc.qnbbs.pojo.DetailExample;
import cn.kgc.qnbbs.pojo.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DetailServiceImpl implements  DetailService {

    @Resource
    DetailMapper detailMapper;
    @Resource
    SortMapper sortMapper;
    @Override
    public List<Detail> selectAll(Integer sortid) {
        List<Detail> details=new ArrayList<>();
       if(sortid!=0){
           DetailExample example=new DetailExample();
           DetailExample.Criteria criteria=example.createCriteria();
           criteria.andSortidEqualTo(sortid);
           details= detailMapper.selectByExample(example);
       }else{
           details= detailMapper.selectByExample(null);
       }
       return details;
    }

    @Override
    public List<Sort> selectAllSort() {
        return sortMapper.selectByExample(null);
    }

    @Override
    public Integer saveDetail(Detail detail) {
        return detailMapper.insertSelective(detail);
    }
}
